#include <check.h>
#include "test_data_format.h"

#include <signal.h>
#include "data_format.h"

static bstring output = NULL; /* Compartida por los tests... */

static void setup (void) {
	output = NULL;
}

static void teardown (void) {
	bdestroy (output);
}

/* Testeo de precondiciones */
START_TEST (test_negative_time)
{
	output = format_time (-1);
}
END_TEST

/* Testeo de funcionalidad */

START_TEST (test_0)
{
	output = format_time (0);
	fail_unless (biseqcstr (output, "00D 00:00:00"));
}
END_TEST

/* Funcionalidad: ver que cada elemento del resultado ande */
START_TEST (test_11s)
{
	output = format_time (11);
	fail_unless (biseqcstr (output, "00D 00:00:11"));
}
END_TEST

START_TEST (test_11m)
{
	output = format_time (11*60);
	fail_unless (biseqcstr (output, "00D 00:11:00"));
}
END_TEST

START_TEST (test_11h)
{
	output = format_time (11*60*60);
	fail_unless (biseqcstr (output, "00D 11:00:00"));
}
END_TEST

START_TEST (test_11D)
{
	output = format_time (11*60*60*24);
	fail_unless (biseqcstr (output, "11D 00:00:00"));
}
END_TEST

/* Funcionalidad: ver que los elementos del resultado anden juntos */
START_TEST (test_all_11s)
{
	output = format_time (11+60*(11+60*(11+24*11)));
	fail_unless (biseqcstr (output, "11D 11:11:11"));
}
END_TEST

/* Funcionalidad: ver que se prefijen 0s antes de los valores <10 */
START_TEST (test_pad_0s)
{
	output = format_time (1+60*(1+60*(1+24*1)));
	fail_unless (biseqcstr (output, "01D 01:01:01"));
}
END_TEST

/* Armado de la test suite */

Suite *data_format_suite (void)
{
	Suite *s = suite_create ("data_format");
	TCase *tc_preconditions = tcase_create ("Precondition");
	TCase *tc_functionality = tcase_create ("Functionality");

	/* Precondiciones */
	tcase_add_checked_fixture (tc_preconditions, setup, teardown);
	tcase_add_test_raise_signal (tc_preconditions, test_negative_time, SIGABRT);
	suite_add_tcase (s, tc_preconditions);

	/* Funcionalidad */
	tcase_add_checked_fixture (tc_functionality, setup, teardown);
	tcase_add_test (tc_functionality, test_0);
	tcase_add_test (tc_functionality, test_11s);
	tcase_add_test (tc_functionality, test_11m);
	tcase_add_test (tc_functionality, test_11h);
	tcase_add_test (tc_functionality, test_11D);
	tcase_add_test (tc_functionality, test_all_11s);
	tcase_add_test (tc_functionality, test_pad_0s);
	suite_add_tcase (s, tc_functionality);

	return s;
}

